<?php
 class Pages extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    
     /** 
     * Insert data for config
     * @author tien.nguyen
     */
    public function getList(){
        $query = $this->db->get('pages');
        $res = $query->result_array();
        return $res;
    }
    
    /**
     * Get page 
     * @author tien.nguyen
     */
    public function getPage($pageId){
        $query = $this->db->get_where('pages', array('PageId' => $pageId));
        return $query->row_array();
    }
    
    /**
     * edit function in config
     * @author tien.nguyen
     */
    public function edit($data, $pageId){
        $data = $this->_convertData($data);
        return $this->db->update('pages', $data, array('PageId' => $pageId));
    }
    
    /**
     * Convert page for page title
     * @author tien.nguyen
     */
    private function _convertData($data){
        $res = array();
        $arr = array('PageId', 'PageTitle', 'PageName', 'PageDetail', 'PageCode');
        foreach($arr as $item){
            if(isset($data[$item])){
                $res[$item] = $data[$item];
            }
        }
        return $res;
    }
 }
?>